-- || Created by Unlimited

MySQL = inherit(Singleton)

local dbHost = "127.0.0.1"
local dbName = "dm-mta"
local dbUser = "root"
local dbPW   = ""

function MySQL:constructor()
	local cString = ("dbname=%s;host=%s"):format(dbName,dbHost)
	self.m_Connection = dbConnect ("mysql",cString,dbUser,dbPW)
	if self.m_Connection then
		print("MySQL-Connection successfully...")
	else
		print("Crit. Error")
		stopResource(getThisResource())
	end
end

function MySQL:isConnected()
	return self.m_Connection
end

function MySQL:query(qry, ...)
	if self:isConnected() then
		local query = dbQuery(self.m_Connection, qry, ...)
		local result, num_rows = dbPoll(query, -1)
		dbFree(query)
		return result, num_rows
	end
end

function MySQL:exec(qry, ...)
	if self:isConnected() then
		return dbExec(self.m_Connection, qry, ...)
	end
end